﻿namespace EcmaDoc.Core.Configuration
{
	using System;
	using System.Collections.Generic;
	using System.Xml;

	/// <summary>
	/// Represents a an external type, as defined in the parser configuration.
	/// </summary>
	internal class ExternalTypeInfo
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ExternalTypeInfo"/> class using the specified <paramref name="infoElement"/>.
		/// </summary>
		/// <param name="infoElement">The configuration element that contais the link data.</param>
		public ExternalTypeInfo(XmlElement infoElement)
		{
			if (infoElement == null)
				throw new ArgumentNullException("infoElement");

			this.Name = infoElement.GetAttribute("name");
			this.Aliases = new List<string>(infoElement.GetAttribute("aliases").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
			this.Links = new List<LinkInfo>();

			foreach (XmlElement linkNode in infoElement.SelectNodes("c:link", ParserConfig.NamespaceManager))
				this.Links.Add(new LinkInfo(linkNode));
		}

		/// <summary>
		/// Gets the name of this type.
		/// </summary>
		public string Name
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the aliases of this type.
		/// </summary>
		public List<string> Aliases
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the links of this type.
		/// </summary>
		public List<LinkInfo> Links
		{
			get;
			private set;
		}
	}
}
